package com.hl.yyx.common.util;

import com.hl.yyx.modules.ums.model.UmsAdmin;

import javax.servlet.http.HttpServletRequest;

public class RequestHolder {

    private static final ThreadLocal<UmsAdmin> userHolder = new InheritableThreadLocal<>();

    private static final ThreadLocal<HttpServletRequest> requestHolder = new InheritableThreadLocal<HttpServletRequest>();

    public static void add(UmsAdmin admin) {
        userHolder.set(admin);
    }

    public static void add(HttpServletRequest request) {
        requestHolder.set(request);
    }

    public static UmsAdmin currentUser() {
        return userHolder.get();
    }

    public static HttpServletRequest currentRequest() {
        return requestHolder.get();
    }

    public static void remove() {
        userHolder.remove();
        requestHolder.remove();
    }
}
